yjx.controller('agencyController', ['$rootScope', '$scope', '$fetch', 'modalService','$timeout','$compile','ipCookie', function ($rootScope, $scope, $fetch,modalService,$timeout,$compile,ipCookie) {
    $scope.code = '';
    $scope.telephone = ''
    $scope.showRelogin = false;
    $scope.okMsgTitle = "恭喜您已完成申请";
    $scope.okMsg = "您可以直接以健康管家的身份登录";
    // var sucMsg = "恭喜您已完成申请！<br>您可以直接以健康管家的身份登录"
    $scope.apply = function () {
        console.log($scope.telephone );
        if(!$scope.telephone || !$scope.telephone.match("^[1][34578][0-9]{9}$") ){
                modalService.mainMsgError("请输入正确格式的手机号");
            return;
        }
        if(!$scope.code) {
            modalService.mainMsgError("请输入邀请码")
            return;
        }
         $fetch.fetch(
             '/user/applyAgent',
             {
                 params:{
                     userId:$rootScope.userId,
                     code:$scope.code,
                     telephone:$scope.telephone
                 }
             }
         ).then(function (data) {
                 var userData = ipCookie('user');
                 userData.userType = 1;
                 ipCookie('user', userData, ipCookiesParam);
                 $rootScope.user.userType = 1;
                 $scope.showRelogin = true;
                // modalService.mainMsgInfo(sucMsg,'','',tologin);
         }).catch(function (e) {
                 modalService.mainMsgError(e.msg);
         })
    }
    $scope.tologin =function(){
        $timeout(function () {
            $scope.tempwx = "components/user/identity/identity.html";
            var html = '<div class="e-detail" ng-include="\'' + $scope.tempwx + '\'"></div>';
            var detailHtml = $compile(html)($scope);
            angular.element(document.querySelector('#m-detail')).append(detailHtml);//后排插入
            angular.element(document.querySelector('#m-detail')).show();
            $rootScope._dCount++;
        })
    }

    function cancel() {
        return
    }
}])